<?php if(!defined('PUBLIC_DIR')) die('No Acces!');

using('System.Data.Sql');
Cnamespace('System.Data.Sql');
class Database implements iDatabase {
	private $dbClass;

	public function __construct($connection, $dbType, $new = false){
		$dbAvaible = array('SQLite3', 'SQLite', 'FireBird', 'InterBase', 'MsSql', 'MySql', 'Oracle', 'PostgreSql');
		if($dbType == 'SQLite3' || $dbType == 'SQLite'){
			if(!(class_exists('SQLite3') && $dbType == 'SQLite3'))
				if(class_exists('SQLiteDatabase'))
					$dbType = 'SQLite';
				else if(class_exists('SQLite3'))
					$dbType = 'SQLite3';
				else
					trigger_error('Brak kontrolera bazy danych ' . $dbType . '.', E_USER_ERROR);
		}
		if(in_array($dbType, $dbAvaible) === true){
			$dbType = ''.$dbType.'DB';
			$this->dbClass = new $dbType($connection, $new);
		}else
			trigger_error('Typ bazy danych nie obsługiwany', E_USER_ERROR);
	}

	public function Query($query){
		return $this->dbClass->Query($query);
	}

	public function GetQuery(){
		return $this->dbClass->GetQuery();
	}

	public function GetResult(){
		return $this->dbClass->GetResult();
	}

	public function NumFields($result = null){
		return $this->dbClass->NumFields($result);
	}

	public function NumRows($result = null){
		return $this->dbClass->NumRows($result);
	}

	public function FetchRow($result = null){
		return $this->dbClass->FetchRow($result);
	}

	public function FetchArray($result = null){
		return $this->dbClass->FetchArray($result);
	}

	public function Close(){
		return $this->dbClass->Close();
	}
}